<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加会员-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../css/font.css">
		<link rel="stylesheet" href="../../css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	    <script src="../../js/jquery-3.1.1.js"></script>
	</head>

	<body>
		<div class="weadmin-body">
			<form class="layui-form">
				
				<div class="layui-form-item">
					<label for="L_email" class="layui-form-label">
		                <span class="we-red">*</span>规约名称
		            </label>
					<div class="layui-input-inline">
						<input type="text" id="straName" name="straName" lay-verify="required" autocomplete="" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="L_username" class="layui-form-label">
		                <span class="we-red">*</span>规约编号
		            </label>
					<div class="layui-input-inline">
						<input placeholder="取值范围0-127" type="text" id="L_username" name="pid" lay-verify="required|pid" autocomplete="off" class="layui-input">
					</div>
					<div class="layui-form-mid layui-word-aux">
						请牢记规约编号
					</div>
				</div>
				<div class="layui-form-item">
				    <label for="L_sex" class="layui-form-label">大端模式</label>
				    <div class="layui-input-block" id="L_sex">
				      <input type="radio" name="bigdian" value="1" title="是" checked>
				      <input type="radio" name="bigdian" value="0" title="否">
				    </div>
				</div>

				<div class="layui-form-item">
					<label for="L_email" class="layui-form-label">
		                <span class="we-red">*</span>长度域偏移
		            </label>
					<div class="layui-input-inline">
						<input type="text" id="L_phone" name="lenOffset" lay-verify="required|intVal" autocomplete="" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="L_email" class="layui-form-label">
		                <span class="we-red">*</span>长度域长度
		            </label>
					<div class="layui-input-inline">
						<input type="text" id="L_email" name="lenrange" lay-verify="required|intVal" autocomplete="off" class="layui-input">
					</div>

				</div>
				<div class="layui-form-item">
					<label for="L_email" class="layui-form-label">
		                <span class="we-red">*</span>长度域值是否包含长度域本身
		            </label>
					<div class="layui-input-block" id="L_sex">
				      <input type="radio" name="lenInfo" value="1" title="是" checked>
				      <input type="radio" name="lenInfo" value="0" title="否">
				    </div>

				</div>
				<div class="layui-form-item">
					<label for="L_email" class="layui-form-label">
		                <span class="we-red">*</span>剩余字节数
		            </label>
					<div class="layui-input-inline">
						<input type="text" id="L_email" name="leftLen"  lay-verify="required|intVal" autocomplete="off" class="layui-input">
					</div>

				</div>
				<div class="layui-form-item">
					<label for="L_email" class="layui-form-label">
		                <span class="we-red">*</span>端口号
		            </label>
					<div class="layui-input-inline">
						<input type="text" id="L_email" name="port"  lay-verify="required|intVal" autocomplete="off" class="layui-input">
					</div>

				</div>
				
				<div class="layui-form-item">
					<label for="L_repass" class="layui-form-label">
              		</label>
					<button class="layui-btn" lay-filter="add" lay-submit="">确定</button>
				</div>
			</form>
		</div>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		
		<script>
			layui.extend({
				admin: '{/}../../js/admin'
			});
			layui.use(['form', 'jquery','util','admin', 'layer'], function() {
				var form = layui.form,
					$ = layui.jquery,
					util = layui.util,
					admin = layui.admin,
					layer = layui.layer;

				//自定义验证规则
				form.verify({
					pid: function(value) {
						if(value < 0 || value > 127) {
							return '规约编号只能在[0,127]区间内';
						}
					},
					intVal: [ /^[0-9]+[0-9]*]*$/, '必须为正整数']
				});
				//失去焦点时判断值为空不验证，一旦填写必须验证

				//监听提交
				form.on('submit(add)', function(data) {
					console.log(data.field);
					var f = data.field;
					//console.log(f.username);
					//console.log(f.sex);				
					//var sex = $('input:radio[name="sex"]:checked').val();
					
					//发异步，把数据提交给php
					debugger;
					$.post("/rpc/addOneStrategy", {"data":f},
						function(data){
							//alert("Data Loaded: " + data.retSig);
							if(data.retSig == 200){
								layer.alert("增加成功", {
									icon: 6
								}, function() {
									//获取提交成功的时间
									var time = new Date();
									var timeNow = util.toDateString(time);
									// 获得frame索引
									var index = parent.layer.getFrameIndex(window.name);
								
			    					var _len = parent.$('#memberList tr').length;
									parent.$('#memberList').append(						
										'<tr data-id="' + f.pid + '">' +
											'<td>'+
												'<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="' + f.pid + '"><i class="layui-icon">&#xe605;</i></div>'+
											'</td>'+
											'<td>' + f.pid + '</td>'+
											'<td>' + f.straName + '</td>'+
											'<td>'+f.bigdian+'</td>'+
											'<td>'+f.lenOffset+'</td>'+
											'<td>'+f.lenrange+'</td>'+
											'<td>'+f.lenInfo+'</td>'+
											'<td>'+f.leftLen+'</td>'+
											'<td>'+f.port+'</td>'+
											'<td class="td-manage">'+
												'<a title="删除" onclick="member_del(this,\'' + f.pid + '\')" href="javascript:;"><i class="layui-icon">&#xe640;</i></a>'+
											'</td>'+
										'</tr>'	
									);
									//关闭当前frame
									parent.layer.close(index);
								});
							}else{
								layer.alert("增加失败，请检查参数")
							}
							
						},"json"
					);
					return false;
				});

			});
		</script>
	</body>

</html>